home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 18 / develop 18 code / OSA Sample / Sources / ObjModelTokens.cp < prev    next >
Encoding:
Text File  |  1994-01-28  |  18.9 KB  |  826 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ObjModelTokens.cp
  3.  
  4.     Contains:    Token classes implementation
  5.  
  6.     Developed by:    
  7.         
  8.         Paul G Smith (commstalk hq & Full Moon Software, Inc)
  9.         
  10.         you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  11.         BUT I prefer to be contacted by e-mail
  12.         AppleLink:     SMITH.PG
  13.         Internet:     SMITH.PG@applelink.apple.com
  14.         
  15.         "SimpliFace" Sample code to accompany develop article
  16.         on techniques for embedding scripts in applications.
  17.  
  18.  
  19.     Apple Event Object Model tokens for SimpliFace
  20.  
  21. */
  22.  
  23.  
  24. #ifndef __MENUS__
  25. #include <Menus.h>
  26. #endif
  27. #ifndef __EVENTS__
  28. #include <Events.h>
  29. #endif
  30. #ifndef __WINDOWS__
  31. #include <Windows.h>
  32. #endif
  33. #ifndef __DIALOGS__
  34. #include <Dialogs.h>
  35. #endif
  36. #ifndef __QUICKDRAW__
  37. #include <Quickdraw.h>
  38. #endif
  39. #ifndef __MEMORY__
  40. #include <Memory.h>
  41. #endif
  42. #ifndef __FILES__
  43. #include <Files.h>
  44. #endif
  45. #ifndef __STANDARDFILE__
  46. #include <StandardFile.h>
  47. #endif
  48. #ifndef __SYSEQU__
  49. #include <SysEqu.h>
  50. #endif
  51. #ifndef __PLSTRINGFUNCS__
  52. #include <PLStringFuncs.h>
  53. #endif
  54.  
  55. #ifndef __AERegistry__
  56. #include <AERegistry.h>
  57. #endif
  58. #ifndef __ASREGISTRY__
  59. #include <ASRegistry.h>
  60. #endif
  61. #ifndef __APPLEEVENTS__
  62. #include <AppleEvents.h>
  63. #endif
  64. #ifndef __AEOBJECTS__
  65. #include <AEObjects.h>
  66. #endif
  67.  
  68. #ifndef __AEOBJECTPACKING__
  69. #include <AEPackObject.h>
  70. #endif
  71.  
  72. #ifndef __AEOMTOKENS__
  73. #include "ObjModelTokens.h"
  74. #endif
  75.  
  76. #ifndef __AEOMEVENTS__
  77. #include "ObjModelEvents.h"
  78. #endif
  79.  
  80. #ifndef __SCRIPTUTILS__
  81. #include "ScriptUtils.h"
  82. #endif
  83.  
  84.  
  85.  
  86. #pragma segment ObjectAccessors
  87.  
  88.  
  89.  
  90. // ------------
  91.  
  92.  
  93. // ------------
  94.  
  95. #pragma trace off
  96.  
  97. // utility routines
  98.  
  99. objModelTokenPtr ObjModelTokenFromDesc(AEDesc *theDesc)
  100. {
  101.     objModelTokenPtr    theToken = nil;
  102.     Size                actSize;
  103.     
  104.     if (theDesc->descriptorType == typeObjModelToken)
  105.         GetRawDataFromDescriptor(theDesc, (Ptr)&theToken, sizeof(theToken), &actSize);
  106.         
  107.     return theToken;
  108. }
  109.  
  110. OSErr DescFromObjModelToken(const objModelTokenPtr theToken, AEDesc *theDesc)
  111. {
  112.     return AECreateDesc(typeObjModelToken, (Ptr)&theToken, sizeof(theToken), theDesc);
  113. }
  114.  
  115.  
  116. // -------------------------------------------------------
  117.  
  118. #pragma segment ObjectAccessors
  119.  
  120. #pragma trace off
  121.  
  122.  
  123. TObjModelToken::TObjModelToken(void)
  124. {
  125.     fTokenClass = typeNull;
  126.     fIsProperty = false;
  127.     fPropertyID = typeNull;
  128.     fTheObject = NULL;
  129. }
  130.  
  131.  
  132. TObjModelToken::TObjModelToken(DescType theTokenClass,
  133.                                 TScriptableObject* theObj)
  134. {
  135.     fTokenClass = theTokenClass;
  136.     fIsProperty = false;
  137.     fPropertyID = typeNull;
  138.     fTheObject = theObj;
  139. }
  140.  
  141.  
  142. TObjModelToken::TObjModelToken(const TObjModelToken& oldObj)
  143. {
  144.     fTokenClass = oldObj.fTokenClass;
  145.     fIsProperty = oldObj.fIsProperty;
  146.     fPropertyID = oldObj.fPropertyID;
  147.     fTheObject = oldObj.fTheObject;
  148. }
  149.  
  150.  
  151. TObjModelToken& TObjModelToken::operator=(const TObjModelToken& oldObj)
  152. {
  153.     if (this != &oldObj)
  154.     {
  155.         fTokenClass = oldObj.fTokenClass;
  156.         fIsProperty = oldObj.fIsProperty;
  157.         fPropertyID = oldObj.fPropertyID;
  158.         fTheObject = oldObj.fTheObject;
  159.     }
  160.     return *this;
  161. }
  162.  
  163.  
  164. TObjModelToken::~TObjModelToken(void)
  165. {
  166.     // nothing to do!
  167. }
  168.  
  169.  
  170. TObjModelToken* TObjModelToken::MakeClone(void)
  171.     return new TObjModelToken(*this);
  172. }
  173.  
  174.  
  175. // support for object accessors
  176.  
  177.  
  178. TObjModelToken* TObjModelToken::MakeNewToken (DescType theTokenClass,
  179.                                             TScriptableObject* theObj)
  180. {
  181.     TObjModelToken    *resultToken = new TObjModelToken(theTokenClass, theObj);
  182.     
  183.     return resultToken;
  184. }
  185.  
  186.  
  187. OSErr TObjModelToken::ResolveElement(DescType desiredClass,
  188.                                     DescType keyForm,
  189.                                     AEDesc *keyData,
  190.                                     TObjModelToken **theResultToken)
  191. {
  192.     OSErr                 err = errAEEventNotHandled;
  193.     TScriptableObject     *theResultObj = NULL;
  194.     
  195.     // this function has been called because no derived class knows
  196.     // how to resolve the specified token
  197.     
  198.     // start by testing keyForm; 
  199.  
  200.     if (!fTheObject)    // can't do it if no object referenced!
  201.         return errAEEventNotHandled;
  202.     else if (keyForm == formName)
  203.     {
  204.         CStr255     nameStr = "";
  205.  
  206.         err = GetPStringFromDescriptor(keyData, (char *)&nameStr);
  207.         
  208.         if (!err)
  209.             err = fTheObject->ResolveElementByName(desiredClass, nameStr, 
  210.                                                     &theResultObj);
  211.     } 
  212.     else if (keyForm == formAbsolutePosition)
  213.     {
  214.         short       index;
  215.  
  216.         err = GetIntegerFromDescriptor(keyData, &index);
  217.         if (index < 0)
  218.         {
  219.             long numElems;
  220.             
  221.             if (fTheObject->CountElements(desiredClass, &numElems) == 0)
  222.                 index = numElems + index + 1;
  223.         }
  224.         
  225.         if (!err)
  226.             err = fTheObject->ResolveElementByIndex(desiredClass, index, 
  227.                                                     &theResultObj);
  228.     }
  229.     else
  230.         err = errAEBadKeyForm;
  231.         
  232.     if (!err)
  233.     {
  234.         *theResultToken = MakeNewToken(desiredClass, theResultObj);
  235.     }
  236.     return err;
  237. }
  238.                                     
  239. OSErr TObjModelToken::ResolveProperty(DescType desiredClass,
  240.                                     DescType keyForm,
  241.                                     AEDesc *keyData,
  242.                                     TObjModelToken **theResultToken)
  243. {
  244.     OSErr             err = errAEEventNotHandled;
  245.     DescType          theProperty;
  246.     Size              actualSize;
  247.     
  248.     if (keyForm == formPropertyID)
  249.     {
  250.         GetRawDataFromDescriptor(keyData, (Ptr)&theProperty,
  251.                                  sizeof(theProperty), &actualSize);
  252.         
  253.         fIsProperty = true;
  254.         fPropertyID = theProperty;
  255.         
  256.         // make clone of this token and return reference to 
  257.         // it in theResultToken (requires use of copy constructors)
  258.         
  259.         *theResultToken = this->MakeClone();
  260.         
  261.         if (*theResultToken)
  262.             err = noErr;
  263.     }
  264.     
  265.     return err;
  266. }
  267.  
  268.  
  269. OSErr TObjModelToken::CallDispatchAppleEvent(AppleEvent *theEvent, 
  270.                                     AppleEvent *theReply, 
  271.                                     AEEventClass theEvtClass,
  272.                                     AEEventID theEvtID)
  273. {
  274.     return this->DispatchAppleEvent(theEvent, theReply, theEvtClass, theEvtID);
  275. }
  276.  
  277.  
  278. OSErr TObjModelToken::DispatchAppleEvent(AppleEvent *theEvent, 
  279.                                     AppleEvent *theReply, 
  280.                                     AEEventClass theEvtClass,
  281.                                     AEEventID theEvtID)
  282. {
  283.     OSErr             err = errAEEventNotHandled;
  284.     
  285.     if (!fTheObject)    // can't do it if no object referenced!
  286.         return err;
  287.  
  288.     if (theEvtClass == kASAppleScriptSuite && theEvtID == kASSubroutineEvent)
  289.     {
  290.         //Trace("Received AS subroutine event (not handled)\n");
  291.     }
  292.     else if (theEvtClass == kAEMiscStandards && theEvtID == kAEDoScript)
  293.     {
  294.         //Trace("Received Do Script event (not handled)\n");
  295.     }
  296.     else if (theEvtClass == kAECoreSuite || theEvtClass == kCoreEventClass)
  297.     {
  298.         switch (theEvtID)
  299.         {
  300.         case kAECountElements:
  301.             err = this->AECountElems(theEvent, theReply);
  302.             break;
  303.         case kAECreateElement:
  304.             err = this->AECreateElem(theEvent, theReply);
  305.             break;
  306.         case kAEDelete:
  307.             err = this->AEDeleteElem(theEvent, theReply);
  308.             break;
  309.         case kAEClose:
  310.             err = this->AECloseObject(theEvent, theReply);
  311.             break;
  312.         case kAEGetData:
  313.             err = this->AEGetObjectData(theEvent, theReply);
  314.             break;
  315.         case kAEOpen:
  316.             err = this->AEOpenObject(theEvent, theReply);
  317.             break;
  318.         case kAESetData:
  319.             err = this->AESetObjectData(theEvent, theReply);
  320.             break;
  321.         }
  322.     }
  323.     return err;
  324. }
  325.                         
  326.  
  327. // hooks into Apple Event handling, only override for special-purposes;
  328. // return noErr if Apple Event was handled within the hook function, or 
  329. // errAEEventNotHandled if it was not handled within the hook function
  330.  
  331. OSErr TObjModelToken::AECountElems        (AppleEvent *theEvent, 
  332.                                         AppleEvent *theReply)
  333. {
  334.     OSErr                 err = errAEEventNotHandled;
  335.     AEDesc                resultDesc;
  336.     Size                theSize;
  337.     DescType            theType, desiredClass;
  338.     long                result;
  339.  
  340.     InitAEDescs(&resultDesc, kEndOfList);
  341.     
  342.     err = AEGetParamPtr(theEvent, keyAEObjectClass, typeType, &theType,
  343.                         (Ptr)&desiredClass, sizeof(DescType), &theSize);
  344.     
  345.     if (!err)
  346.         err = fTheObject->CountElements(desiredClass, &result);
  347.         
  348.     if (!err)
  349.         err = AECreateDesc(typeLongInteger, &result, sizeof(long), &resultDesc);
  350.         
  351.     if (!err && theReply->descriptorType != typeNull)
  352.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  353.     
  354.     DisposeAEDescs(&resultDesc, kEndOfList);
  355.     
  356.     return err;
  357. }
  358.  
  359. OSErr TObjModelToken::AECreateElem        (AppleEvent *theEvent, 
  360.                                         AppleEvent *theReply)
  361. {
  362.     //     get insertionloc
  363.     //        resolve insertion point
  364.     //     get desired object class
  365.     //  ask object at insertion point to create new object
  366.     //    get new object's data (optional param)
  367.     //        save data
  368.     //    get new object's properties record  (optional param)
  369.     //        save properties
  370.     //    ask new object to create it's own object specifier
  371.     //    return object specifier as result
  372.     OSErr                 err = errAEEventNotHandled;
  373.     AEDesc                resultDesc, dataObject;
  374.     AEDesc                insLocParam, insLocObject, theTokenDesc;
  375.     AERecord            insLocRec, dataPropParam;
  376.     TObjModelToken         *theToken = NULL;
  377.     Size                theSize;
  378.     DescType            theType, position;
  379.     DescType            theClass;
  380.     
  381.     InitAEDescs(&insLocParam, &insLocRec, &insLocObject, &theTokenDesc,
  382.                 &resultDesc, &dataObject, &dataPropParam, kEndOfList);
  383.     
  384.     err = AEGetParamPtr(theEvent, keyAEObjectClass, typeType, &theType,
  385.                         (Ptr)&theClass, sizeof(DescType), &theSize);
  386.     if (!err)
  387.         err = AEGetParamDesc(theEvent, keyAEInsertHere, typeInsertionLoc, &insLocParam);
  388.     if (err)
  389.     {
  390.         TObjModelToken    *aApplicationToken = NULL;
  391.         
  392.         position = kAEEnd;
  393.         err = MakeAppToken(&aApplicationToken);
  394.         if (!err)
  395.         {
  396.             theToken = aApplicationToken;
  397.             DescFromObjModelToken(theToken, &theTokenDesc);
  398.         }
  399.     }
  400.     else
  401.     {
  402.         // coerce the insertion loc record to an AE record.
  403.         err = AECoerceDesc(&insLocParam, typeAERecord, &insLocRec);
  404.         if (!err)
  405.             err = AEGetKeyPtr(&insLocRec, keyAEPosition, typeEnumeration, &theType, 
  406.                                 (Ptr)&position, sizeof(DescType), &theSize);
  407.         if (!err)    //    Get the object reference
  408.             err = AEGetKeyDesc(&insLocRec, keyAEObject, 
  409.                                 typeWildCard, &insLocObject);
  410.     
  411.         if (!err)
  412.         {
  413.             err = AEResolve(&insLocObject, kAEIDoMinimum, &theTokenDesc);
  414.             
  415.             if (!err)
  416.                 theToken = ObjModelTokenFromDesc(&theTokenDesc);
  417.         }
  418.     }
  419.  
  420.     if (theToken)
  421.     {
  422.         TScriptableObject     *theNewObj = NULL;
  423.         TObjModelToken        *theNewToken = NULL;
  424.         TScriptableObject    *containerObj = NULL;
  425.         AERecord            *dataPropPtr = NULL;
  426.  
  427.         err = theToken->GetTokenObj()->ResolveContainer(&containerObj);
  428.  
  429.         if (position == kAEReplace && 
  430.              (theToken->GetTokenClass() == cApplication
  431.               || theToken->GetTokenClass() == cDocument))
  432.             err = errAEEventNotHandled;
  433.         else
  434.         {
  435.             err = AEGetParamDesc(theEvent, keyAEData, typeWildCard, &dataObject);
  436.             err = AEGetParamDesc(theEvent, keyAEPropData, typeAERecord, 
  437.                                     &dataPropParam);
  438.             if (!err)
  439.                 dataPropPtr = &dataPropParam;
  440.             // ignore errors if above calls fail
  441.             err = theToken->GetTokenObj()->CreateNewElement(theClass, position, 
  442.                                             &dataObject, dataPropPtr,
  443.                                             containerObj, &theNewObj);
  444.             if (!err)
  445.                 theNewToken = MakeNewToken(theClass, theNewObj);
  446.                 
  447.             if (!err && theNewToken)
  448.                 theNewToken->GetTokenObj()->GetObjectSpecifier(&resultDesc);
  449.             if (theNewToken)
  450.                 delete theNewToken;
  451.         }
  452.     }
  453.     
  454.     if (!err && (resultDesc.descriptorType != typeNull) 
  455.         && (theReply->descriptorType != typeNull))
  456.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  457.     
  458.     AEDisposeToken(&theTokenDesc); // DO NOT CALL until done with 'theToken'
  459.     DisposeAEDescs(&insLocParam, &insLocRec, &insLocObject,
  460.                     &resultDesc, &dataObject, &dataPropParam, kEndOfList);
  461.     return err;
  462. }
  463.  
  464. OSErr TObjModelToken::AEDeleteElem        (AppleEvent *theEvent, 
  465.                                         AppleEvent *theReply)
  466. {
  467.     OSErr         err = fTheObject->DeleteObject();
  468.     
  469.     return err;
  470. }
  471.  
  472. OSErr TObjModelToken::AECloseObject       (AppleEvent *theEvent, 
  473.                                         AppleEvent *theReply)
  474. {
  475.     return fTheObject->CloseObject();
  476. }
  477.  
  478. OSErr TObjModelToken::AEGetObjectData   (AppleEvent *theEvent, 
  479.                                         AppleEvent *theReply)
  480. {
  481.     OSErr         err = errAEEventNotHandled;
  482.     AEDesc        resultDesc;
  483.  
  484.     resultDesc.dataHandle = NULL;
  485.  
  486.     if (fIsProperty)
  487.     {
  488.         DescType        wantType, actualType;
  489.         Size            actualSize;
  490.         
  491.         err = AEGetParamPtr(theEvent, keyAERequestedType, typeType, &actualType,
  492.                             (Ptr)&wantType, sizeof(DescType), &actualSize);
  493.         if (err)
  494.             wantType = typeWildCard;
  495.         
  496.         err = fTheObject->GetProperty(fPropertyID, wantType, &resultDesc);
  497.     }
  498.     else
  499.     {
  500.         err = fTheObject->GetData(&resultDesc);
  501.         if (err == errAEEventNotHandled)
  502.             err = AEGetParamDesc(theEvent, keyDirectObject, 
  503.                                     typeObjectSpecifier, &resultDesc);
  504.     }
  505.     
  506.     if (!err && theReply->descriptorType != typeNull)
  507.         err = AEPutParamDesc(theReply, keyDirectObject, &resultDesc);
  508.     
  509.     AEDisposeDesc(&resultDesc);
  510.     
  511.     return err;
  512. }
  513.  
  514. OSErr TObjModelToken::AEOpenObject      (AppleEvent *theEvent, 
  515.                                         AppleEvent *theReply)
  516. {
  517.     return fTheObject->OpenObject();
  518. }
  519.  
  520. OSErr TObjModelToken::AESetObjectData   (AppleEvent *theEvent, 
  521.                                         AppleEvent *theReply)
  522. {
  523.     OSErr     err = errAEEventNotHandled;
  524.     AEDesc    dataDesc;
  525.  
  526.     dataDesc.dataHandle = NULL;
  527.     
  528.     err = AEGetParamDesc(theEvent, keyAEData, typeWildCard, &dataDesc);
  529.     
  530.     if (fIsProperty)
  531.         err = fTheObject->SetProperty(fPropertyID, &dataDesc);
  532.     else
  533.         err = fTheObject->SetData(&dataDesc);
  534.         
  535.     AEDisposeDesc(&dataDesc);
  536.     
  537.     return err;
  538. }
  539.  
  540.  
  541. // -------------------------------------------------------
  542.  
  543.  
  544.  
  545. #pragma segment Main
  546.     
  547. // object accessors 
  548.  
  549.  
  550. OSErr MakeAppToken(TObjModelToken** theApplicationToken)
  551. {
  552.     OSErr               err = errAEEventNotHandled;
  553.  
  554.     *theApplicationToken = new TObjModelToken(cApplication, gSimpliFace);
  555.         
  556.     if (theApplicationToken)
  557.         err = 0;
  558.     else
  559.         err = -108; // out of memory
  560.  
  561.     return err;
  562. }
  563.  
  564.  
  565. pascal OSErr PropertyFromNullAccessor   (DescType desiredClass,
  566.                                                 AEDesc *containerToken,
  567.                                                 DescType containerClass,
  568.                                                 DescType keyForm,
  569.                                                 AEDesc *keyData,
  570.                                                 AEDesc *theToken,
  571.                                                 long theRefCon)
  572. {
  573.     OSErr               err = errAEEventNotHandled;
  574.     objModelTokenPtr     theResolvedToken = NULL;
  575.     TObjModelToken        *aApplicationToken = NULL;
  576.  
  577.     if ((desiredClass != cProperty) || (containerClass != typeNull))
  578.         return(errAEWrongDataType);
  579.     
  580.     // we assume property being requested is an application property, 
  581.     // and create a temporary application token
  582.     err = MakeAppToken(&aApplicationToken);
  583.     if (!err)
  584.     {
  585.         err = DescFromObjModelToken((const objModelTokenPtr)aApplicationToken, theToken);
  586.     
  587.         if (!err && theToken)
  588.         {    // ask the temporary application token to resolve the property
  589.             // (this step creates a new token)
  590.             err = aApplicationToken->ResolveProperty(desiredClass, keyForm, keyData, &theResolvedToken);
  591.             if (!err && theResolvedToken)
  592.             {
  593.                 err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  594.             }
  595.         }
  596.         
  597.         if (aApplicationToken)
  598.             delete aApplicationToken;    // dispose of the temporary application token
  599.     }
  600.     return err;
  601. }
  602.                                                 
  603.  
  604. pascal OSErr AppTokenFromNullAccessor  (DescType desiredClass,
  605.                                         AEDesc *containerToken,
  606.                                         DescType containerClass,
  607.                                         DescType keyForm,
  608.                                         AEDesc *keyData,
  609.                                         AEDesc *theToken,
  610.                                         long theRefCon)
  611. {
  612.     OSErr               err = errAEEventNotHandled;
  613.     TObjModelToken    *aApplicationToken = NULL;
  614.     
  615.     if ((desiredClass != cApplication) || (containerClass != typeNull))
  616.         return(errAEWrongDataType);
  617.     
  618.     err = MakeAppToken(&aApplicationToken);
  619.  
  620.     if (!err)
  621.         err = DescFromObjModelToken((const objModelTokenPtr)aApplicationToken, 
  622.                                     theToken);
  623.      
  624.     return(err);
  625. }
  626.                                                 
  627.  
  628. pascal OSErr StdObjectFromNullAccessor   (DescType desiredClass,
  629.                                             AEDesc *containerToken,
  630.                                             DescType containerClass,
  631.                                             DescType keyForm,
  632.                                             AEDesc *keyData,
  633.                                             AEDesc *theToken,
  634.                                             long theRefCon)
  635. {
  636.     OSErr               err = errAEEventNotHandled;
  637.     TObjModelToken    *aApplicationToken = NULL;
  638.     objModelTokenPtr     theResolvedToken = NULL;
  639.     
  640.     if (containerClass != typeNull)
  641.         return(errAEWrongDataType);
  642.     
  643.     err = MakeAppToken(&aApplicationToken);
  644.     
  645.     if (!err)
  646.     {
  647.         err = aApplicationToken->ResolveElement(desiredClass, keyForm, 
  648.                                                 keyData, &theResolvedToken);
  649.         if (!err && theResolvedToken)
  650.         {
  651.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, 
  652.                                         theToken);
  653.         }
  654.         delete aApplicationToken;
  655.     }
  656.  
  657.     return(err);
  658. }
  659.                                                 
  660.  
  661.                                                 
  662.  
  663. pascal OSErr StdObjectAccessor (DescType desiredClass,
  664.                                         AEDesc *containerToken,
  665.                                         DescType containerClass,
  666.                                         DescType keyForm,
  667.                                         AEDesc *keyData,
  668.                                         AEDesc *theToken,
  669.                                         long theRefCon)
  670. {
  671.     OSErr err = errAEEventNotHandled;
  672.     objModelTokenPtr theContToken = ObjModelTokenFromDesc(containerToken);
  673.     objModelTokenPtr theResolvedToken = nil;
  674.     
  675.     if (theToken)
  676.     {
  677.         err = theContToken->ResolveElement(desiredClass, keyForm, keyData, &theResolvedToken);
  678.         if ((err == 0) && theResolvedToken)
  679.         {
  680.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  681.         }
  682.             
  683.     }
  684.     
  685.     return err;
  686. }
  687.                                         
  688.                                     
  689. pascal OSErr StdPropertyAccessor(DescType desiredClass,
  690.                                         AEDesc *containerToken,
  691.                                         DescType containerClass,
  692.                                         DescType keyForm,
  693.                                         AEDesc *keyData,
  694.                                         AEDesc *theToken,
  695.                                         long theRefCon)
  696. {
  697.     OSErr err = errAEEventNotHandled;
  698.     objModelTokenPtr theContToken = ObjModelTokenFromDesc(containerToken);
  699.     objModelTokenPtr theResolvedToken = nil;
  700.     
  701.     if (theContToken && theToken)
  702.     {
  703.         err = theContToken->ResolveProperty(desiredClass, keyForm, keyData, &theResolvedToken);
  704.         if ((err == 0) && theResolvedToken)
  705.         {
  706.             err = DescFromObjModelToken((const objModelTokenPtr)theResolvedToken, theToken);
  707.         }
  708.             
  709.     }
  710.     
  711.     return err;
  712. }
  713.                                         
  714.  
  715. // object support callbacks
  716.  
  717. pascal OSErr StdCountProc        (DescType desiredClass,
  718.                                         DescType containerClass,
  719.                                         AEDesc *containerToken,
  720.                                         long *result)
  721. {
  722.     OSErr                 err = errAEEventNotHandled;
  723.     objModelTokenPtr     theToken = ObjModelTokenFromDesc(containerToken);
  724.  
  725.     if (theToken)
  726.         err = theToken->GetTokenObj()->CountElements(desiredClass, result);
  727.     
  728.     return err;
  729. }
  730.                                         
  731.                                     
  732. pascal OSErr StdCompareProc    (DescType comparisonOperator,
  733.                                         AEDesc object,
  734.                                         DescType objOrDescToCompare,
  735.                                         Boolean& result)
  736. {
  737.     OSErr err = errAEEventNotHandled;
  738.     
  739.     
  740.     return err;
  741. }
  742.  
  743.                                             
  744. pascal OSErr StdDisposeToken   (AEDesc *unneededToken)
  745. {
  746.     OSErr err =    errAEEventNotHandled;
  747.  
  748.     if (unneededToken)
  749.     {
  750.         objModelTokenPtr theToken = ObjModelTokenFromDesc(unneededToken);
  751.         if (theToken)
  752.         {
  753.             delete theToken;
  754.             err = AEDisposeDesc(unneededToken);
  755.             unneededToken->dataHandle = NULL; // in case OSL deletes us twice
  756.         }
  757.     }
  758.     return err;
  759. }
  760.  
  761.  
  762.  
  763. // -------setup
  764.  
  765.  
  766.  
  767. OSErr InstallAccessors(void);
  768.  
  769. OSErr DeInstallAccessors(void);
  770.  
  771.  
  772. // #pragma segment ObjectInit
  773.  
  774. // set up object model handlers
  775. OSErr SFinitAEobjects(void)
  776. {
  777.     OSErr err = 0;
  778.     
  779.     err = InstallAccessors();
  780.     
  781.     return err;
  782. }
  783.  
  784. // detach object model handlers & shut down
  785. OSErr SFendAEobjects(void)
  786. {
  787.     OSErr err = 0;
  788.     
  789.     err = DeInstallAccessors();
  790.     
  791.     return err;
  792. }
  793.  
  794.  
  795. // installation
  796.  
  797. OSErr InstallAccessors(void)
  798. {
  799.     OSErr err = 0;
  800.     
  801.     if (!err) err = AEInstallObjectAccessor(cApplication, typeNull, (accessorProcPtr)&AppTokenFromNullAccessor, (long)cApplication, false);
  802.     if (!err) err = AEInstallObjectAccessor(typeWildCard, typeNull, (accessorProcPtr)&StdObjectFromNullAccessor, 0, false);
  803.     if (!err) err = AEInstallObjectAccessor(typeWildCard, typeObjModelToken, (accessorProcPtr)&StdObjectAccessor, 0, false);
  804.  
  805.     if (!err) err = AEInstallObjectAccessor(cProperty, typeNull, (accessorProcPtr)&PropertyFromNullAccessor, (long)cProperty, false);
  806.     if (!err) err = AEInstallObjectAccessor(cProperty, typeObjModelToken, (accessorProcPtr)&StdPropertyAccessor, (long)cProperty, false);
  807.     
  808.     if (!err) err = AESetObjectCallbacks(   (compareProcPtr)&StdCompareProc, 
  809.                                             (countProcPtr)&StdCountProc, 
  810.                                             (disposeTokenProcPtr)&StdDisposeToken,
  811.                                             nil, nil, nil, nil);
  812.     
  813.     return err;
  814. }
  815.  
  816. OSErr DeInstallAccessors(void)
  817. {
  818.     OSErr err = 0;
  819.  
  820.     
  821.     return err;
  822. }
  823.  
  824.  
  825.